package main

import (
	"fmt"
	"reflect"
)

// 定义学生结构体
type Studentt struct {
	Name string
	Age  int
}

// 定义函数操作结构体进行反射
func TestStudentStruct(a interface{}) {
	// a转reflect.Value类型
	val := reflect.ValueOf(a)
	fmt.Println(val) // {二狗 18}

	numField := val.Elem().NumField()
	fmt.Println(numField)

	// 修改字段的值
	val.Elem().Field(0).SetString("张三")
}
func main() {
	student := Studentt{
		Name: "二狗",
		Age:  18,
	}
	TestStudentStruct(&student)
	fmt.Println(student)
}
